import { i18n } from '@/utils/language';

export class Validation {
  static required(fieldName: string) {
    return {
      required: true,
      message: i18n.t('fieldRequired', { field: i18n.t(fieldName) })
    };
  }

  static minLength(length: number) {
    return {
      min: length,
      message: i18n.t('fieldMismatchMinLength', { number: length })
    };
  }

  static maxLength(length: number) {
    return {
      max: length,
      message: i18n.t('fieldMismatchMaxLength', { number: length })
    };
  }

  static match(pattern: string, fieldName: string) {
    return {
      pattern: pattern,
      message: i18n.t('fieldMismatchPattern', { field: i18n.t(fieldName) })
    };
  }

  // Indicates the type of validator to use, reference to https://github.com/yiminghe/async-validator#type
  static type(type: string, fieldName: string) {
    return {
      type: type,
      message: i18n.t('fieldMismatchType', { field: i18n.t(fieldName) })
    };
  }

  static customizedValidator(validator: Function) {
    return {
      validator: validator
    };
  }
}

export default Validation;
